// packageQuestionnaire/pages/result/result.js
import {getResult} from "../../../service/Questionnaire";
import {post} from "../../../utils/Notification";
import Storage from "../../../utils/Storage";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isLoading: true,
        result: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.data._options = options;
        this.getResult()
    },

    /*
    * 获取评测结果
    * */
    getResult: async function () {
        try {
            let res = await getResult();
            let options = this.data._options;
            options.from !== "register" ? post({
                name: "questionnaire",
                info: res
            }) : null;
            this.setData({result: res})
        } catch (e) {
            console.error(e)
        } finally {
            this.setData({isLoading: false})
        }
    },

    /*
    * 点击返回
    * */
    onButton: function (e) {
        let name = e.currentTarget.dataset.name;
        let options = this.data._options;
        if (name === "back") {
            if (options.from === "register") {
                wx.reLaunch({url: "/pages/home/index/index"});
            } else {
                wx.navigateBack();
            }
        } else {
            if (options.from === "register") {
                wx.redirectTo({url: "/packageQuestionnaire/pages/list/list?from=register"})
            } else {
                wx.redirectTo({url: "/packageQuestionnaire/pages/list/list"})
            }
        }
    }
})